﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using SimpleHttpServer.GuestBook;

namespace SimpleHttpServer
{
    public static class HtmlFormatter
    {
        public static string CreateTable(IEnumerable<GuestBookEntry> guestBookEntries)
        {
            string path = Path.Combine(CommonHelper.AppPath, "Templates\\MainTemplate.htm");
            StringBuilder templateBuilder = new StringBuilder(File.ReadAllText(path));

            string table = "<table border=\"1\"><tr><td><b>UserName</b></td><td><b>Message</b></td></tr>";

            foreach (var guestBookEntry in guestBookEntries)
            {
                table += "<tr><td>" + guestBookEntry.UserName + "</td><td>" + guestBookEntry.Message + "</td></tr>";
            }

            table += "</table>";



            templateBuilder = templateBuilder.Replace("#guestbooktable#", table);
            templateBuilder = templateBuilder.Replace("#mode#", Settings.PersistanceMode.ToString());

    

            return templateBuilder.ToString();

        }


        
    }
}
